package com.example.park2212.sign

import android.widget.TextView
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.lib_base.entity.SignBeanItem
import com.example.park2212.R

class SignAdapter:BaseMultiItemQuickAdapter<SignBeanItem,BaseViewHolder>() {

    init {
        addItemType(0, R.layout.item_sign)
        addItemType(1,R.layout.item_sign2)
    }

    override fun convert(helper: BaseViewHolder, item: SignBeanItem) {
        if(item.type==0){
            val split = item.morningCheckIn.split(" ")
            helper.setText(R.id.sign_date,split[0].replaceFirst(Regex("-"),"年").replaceFirst(Regex("-"),"月")+"日")
            helper.setText(R.id.sign_time,"上班：${split[1]}")
            helper.setText(R.id.sign_location,item.location)
            val tv_status = helper.getView<TextView>(R.id.sign_status)
            tv_status.setText(item.status)
            setStatus(item.status,tv_status)
        }else{
            val split = item.afternoonCheckIn.split(" ")
            helper.setText(R.id.sign_date2,split[0].replaceFirst("-","年").replaceFirst("-","月")+"日")
            helper.setText(R.id.sign_time2,"下班：${split[1]}")
            helper.setText(R.id.sign_location2,item.location)
            val tv_status = helper.getView<TextView>(R.id.sign_status2)
            tv_status.setText(item.status)
            setStatus(item.status,tv_status)
        }
    }
    fun setStatus(status: String,tv:TextView){
        if(status=="正常"){
            tv.setTextColor(context.getColor(R.color.green))
            tv.setBackgroundResource(R.drawable.shape_status)
        }else if(status=="早退"){
            tv.setTextColor(context.getColor(R.color.blue))
            tv.setBackgroundResource(R.drawable.shape_zhanyong)
        }else {
            tv.setTextColor(context.getColor(R.color.orange))
            tv.setBackgroundResource(R.drawable.shape_weihu)
        }
    }

}